package com.eh.observer;

import com.eh.observer.jdk_observer.observable.JdkWeatherData;
import com.eh.observer.jdk_observer.observer.JdkCurrentConditionDisplay;
import com.eh.observer.observer.Observer;
import com.eh.observer.observer.impl.CurrentConditionDisplay;
import com.eh.observer.subject.impl.WeatherData;

import java.util.Observable;

/**
 * Created by David on 2016/4/23.
 */
public class WeatherStation {
    public static void main(String[] args) {
        WeatherData w = new WeatherData();
        Observer o = new CurrentConditionDisplay();
        w.registerObserver(o);
        w.setMeasurements(27f, 200f);
        w.setMeasurements(23f, 180f);
        w.setMeasurements(32f, 190f);

        System.out.println("\n===============JDK 观察者模式===============\n");

        JdkWeatherData jdkWeatherData = new JdkWeatherData();
        java.util.Observer observer = new JdkCurrentConditionDisplay();
        jdkWeatherData.addObserver(observer);
        jdkWeatherData.setMeasurements(27f, 200f);
        jdkWeatherData.setMeasurements(23f, 180f);
        jdkWeatherData.setMeasurements(32f, 190f);
    }
}
